#_*_ coding: utf-8 _*_
from django.db import models


# Create your models here.
class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ['name']
        verbose_name = u"издатель"
        verbose_name_plural = u"издатели"


class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)
    email = models.EmailField()

    def __unicode__(self):
        return self.first_name + " " + self.last_name

    class Meta:
        # ordering=['name']
        verbose_name = u"автор"
        verbose_name_plural = u"авторы"

class News(models.Model):
    title = models.CharField(max_length=100)
    text = models.TextField()
    authors = models.ManyToManyField(Author)
    add_date = models.DateField()

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = u"новость"
        verbose_name_plural = u"новости"


class Book(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher)
    publication_date = models.DateField()

    def __unicode__(self):
        return self.title

    class Meta:
        # ordering=['name']
        verbose_name = u"книга"
        verbose_name_plural = u"книги"


class Category(models.Model):
    title = models.CharField(max_length=50)

    def __unicode__(self):
        return self.title

    class Meta:
        # ordering=['name']
        verbose_name = u"раздел"
        verbose_name_plural = u"разделы"


class Section(models.Model):
    title = models.CharField(max_length=50)
    category = models.ManyToManyField(Category)

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = u"секция"
        verbose_name_plural = u"секции"


class Documents(models.Model):
    section = models.ManyToManyField(Section)
    title = models.CharField(max_length=50)
    description = models.TextField(max_length=500)
    authors = models.ManyToManyField(Author)
    post_date = models.DateField()
    material = models.FileField(upload_to="Docs")

    def __unicode__(self):
        return self.title

    class Meta:
        # ordering=['name']
        verbose_name = u"документ"
        verbose_name_plural = u"документы"
